package com.jzlin.alltools.service;

import cn.hutool.core.util.StrUtil;
import com.jzlin.alltools.external.uapi.UAPIService;
import com.jzlin.alltools.external.uapi.dto.IPInfoDTO;
import com.jzlin.alltools.utils.IpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * 在线工具功能实现.
 *
 * @author linjz
 * @date 2024/9/12
 */
@Service
public class ToolSupportService {

    @Autowired
    private UAPIService uapiService;

    /**
     * 获取IP信息
     * @param ip
     * @return
     */
    public IPInfoDTO getIPInfo(String ip, HttpServletRequest request) {
        if (StrUtil.isBlank(ip)) {
            ip = IpUtils.getClientIp(request);
        }

        return uapiService.getIpInfo(ip);
    }
}
